package com.tyj.movie.controller;


import com.tyj.movie.entity.MovieTheatre;
import com.tyj.movie.entity.MovieTheatreServer;
import com.tyj.movie.entity.MovieTheatreShow;
import com.tyj.movie.service.MovieTheatreService;
import com.tyj.movie.service.MovieTheatreShowService;
import com.tyj.movie.vo.MovieTheatreShowVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyj
 * @since 2021-06-28
 */
@RestController
@RequestMapping("/movie/show")
public class MovieTheatreShowController {

    @Autowired
    MovieTheatreService movieTheatreService;

    @Autowired
    MovieTheatreShowService movieTheatreShowService;

    @RequestMapping("/queryMovieShow/{movieTheatreId}")
    public ModelAndView query(@PathVariable("movieTheatreId") Long movieTheatreId){
        ModelAndView modelAndView=new ModelAndView();
        //查询当前影院
        MovieTheatre movieTheatre = movieTheatreService.getById(movieTheatreId);
        modelAndView.addObject("movieTheatre",movieTheatre);

        //查询当前影院放映
        List<MovieTheatreShowVo> movieTheatreShowVos =movieTheatreShowService.queryShowByMovieTheatreId(movieTheatreId);
        modelAndView.addObject("movieTheatreShowVos",movieTheatreShowVos);
        modelAndView.setViewName("movieTheatreShow");
        return modelAndView;
    }

    @RequestMapping("/add")
    public ModelAndView movieTheatreShowAdd(MovieTheatreShow movieTheatreShow){
        movieTheatreShowService.save(movieTheatreShow);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("redirect:/movie/show/queryMovieShow/"+movieTheatreShow.getMovieTheatreId());
        return modelAndView;
    }
}

